package com.hssy.wululuaplan.service.impl;

import com.hssy.wululuaplan.entity.SysUser;
import com.hssy.wululuaplan.mapper.SysUserMapper;
import com.hssy.wululuaplan.service.SysUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hssy.wululuaplan.utils.JwtUtils;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * <p>
 * 系统用户 服务实现类
 * </p>
 *
 * @author Mr.Hongtao
 * @since 2025-06-18
 */
@Service
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements SysUserService {

    @Override
    public Integer getUserId(String token) {
        Map<String, Object> map = JwtUtils.checkToken(token);
        return (Integer) map.get("userId");
    }

    @Override
    public SysUser getUserInfo(String token) {
        Integer userId = this.getUserId(token);
        SysUser sysUser = baseMapper.selectById(userId);
        SysUser entity = new SysUser();
        entity.setUsername(sysUser.getUsername());
        return entity;
    }
}
